package br.com.inovati.linkers.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import br.com.inovati.linkers.enuns.Tipos;

@Entity
@Table(name = "emails")
public class Emails implements Serializable {

	private static final long serialVersionUID = -1071914284536470863L;

	@Id
	@Column(name = "email_id")
	@SequenceGenerator(name = "seq_email", sequenceName = "seq_email", allocationSize = 1)
	@GeneratedValue(generator = "seq_email", strategy = GenerationType.SEQUENCE)
	private Long id;

	// Relacionamento com enuns
	@Enumerated(EnumType.STRING)
	@Column(name = "tipo_enum", length = 1, columnDefinition = "Integer")
	private Tipos tipo;

	// Relacionamento com outras tabelas
	// OK
	@ManyToOne
	@JoinColumn(name = "fk_usuario_id", referencedColumnName = "usuario_id")
	private Usuarios usuario;

	@ManyToOne
	@JoinColumn(name = "fk_email_id")
	private Emails email;

	@ManyToMany
	@JoinTable(name = "email_grupo", joinColumns = @JoinColumn(name = "email_id"), inverseJoinColumns = @JoinColumn(name = "grupo_id"))
	private List<Grupos> grupo;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Tipos getTipo() {
		return tipo;
	}

	public void setTipo(Tipos tipo) {
		this.tipo = tipo;
	}

	public Usuarios getUsuario() {
		return usuario;
	}

	public void setUsuario(Usuarios usuario) {
		this.usuario = usuario;
	}

	public Emails getEmail() {
		return email;
	}

	public void setEmail(Emails email) {
		this.email = email;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Emails other = (Emails) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Emails [id=" + id + ", tipo=" + tipo + ", usuario=" + usuario
				+ ", email=" + email + "]";
	}
}
